package com.packenius.library.xspdf;

/**
 * @author Christian Packenius, 2013.
 */
class XSFontTypeAndEncodingInformation {
  final XSFontType fontType;

  /**
   * Font encoding. <i>null</i> is standard encoding.
   */
  final XSAlternativeFontEncoding fontEncoding;

  /**
   * Constructor.
   * 
   * @param fontType
   * @param fontEncoding
   */
  public XSFontTypeAndEncodingInformation(XSFontType fontType, XSAlternativeFontEncoding fontEncoding) {
    this.fontType = fontType;
    this.fontEncoding = fontEncoding;
  }

  /**
   * @see java.lang.Object#equals(java.lang.Object)
   */
  @Override
  public boolean equals(Object o) {
    if (o == null || !(o instanceof XSFontTypeAndEncodingInformation)) {
      return false;
    }
    XSFontTypeAndEncodingInformation o2 = (XSFontTypeAndEncodingInformation) o;
    if (!o2.fontType.equals(fontType)) {
      return false;
    }
    if (fontEncoding != null && o2.fontEncoding != null) {
      if (!o2.fontEncoding.equals(fontEncoding)) {
        return false;
      }
    } else if (fontEncoding != null || fontEncoding != null) {
      return false;
    }
    return true;
  }

  /**
   * @see java.lang.Object#hashCode()
   */
  @Override
  public int hashCode() {
    int typeID = fontType.ordinal() << 16;
    int encID = fontEncoding == null ? 0 : Integer.parseInt(fontEncoding.getID());
    return typeID | encID;
  }
}
